<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:include="include :: header('修改设备管理表')" />
    <th:block th:include="include :: datetimepicker-css" />
  </head>
  <body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
      <form
        class="form-horizontal m"
        id="form-Gzmx_device-edit"
        th:object="${gzmx_device}"
      >
        <input name="id" th:field="*{id}" type="hidden" />
        <input
          id="dev_azdw1_name"
          name="dev_azdw1_name"
          th:field="*{dev_azdw1_name}"
          class="form-control"
          style="display: none"
          type="text"
        />
        <input
          id="dev_azdw2_name"
          name="dev_azdw2_name"
          th:field="*{dev_azdw2_name}"
          class="form-control"
          style="display: none"
          type="text"
        />
        <input
          id="dev_azdw3_name"
          name="dev_azdw3_name"
          th:field="*{dev_azdw3_name}"
          class="form-control"
          style="display: none"
          type="text"
        />
        <input
          id="dev_azdw4_name"
          name="dev_azdw4_name"
          th:field="*{dev_azdw4_name}"
          class="form-control"
          style="display: none"
          type="text"
        />
        <input
          id="dev_azdw5_name"
          name="dev_azdw5_name"
          th:field="*{dev_azdw5_name}"
          class="form-control"
          style="display: none"
          type="text"
        />
        <input
          id="dev_sblx_name"
          name="dev_sblx_name"
          th:field="*{dev_sblx_name}"
          class="form-control"
          style="display: none"
          type="text"
        />

        <div class="form-group">
          <label class="col-sm-3 control-label is-required">设备名称：</label>
          <div class="col-sm-8">
            <input
              name="dev_name"
              id="dev_name"
              th:field="*{dev_name}"
              class="form-control"
              type="text"
              required
            />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label is-required">规格型号：</label>
          <div class="col-sm-8">
            <input
              name="dev_ggxh"
              id="dev_ggxh"
              th:field="*{dev_ggxh}"
              class="form-control"
              type="text"
              required
            />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label is-required">生产厂家：</label>
          <div class="col-sm-8">
            <input
              name="dev_sccj"
              id="dev_sccj"
              th:field="*{dev_sccj}"
              class="form-control"
              type="text"
              required
            />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label is-required">出厂日期：</label>
          <div class="col-sm-3">
            <div class="input-group date">
              <input
                name="dev_ccrq"
                th:value="${#dates.format(gzmx_device.dev_ccrq, 'yyyy-MM-dd')}"
                class="form-control"
                placeholder="yyyy-MM-dd"
                type="text"
                required
              />
              <span class="input-group-addon"
                ><i class="fa fa-calendar"></i
              ></span>
            </div>
          </div>
          <label class="col-sm-2 control-label is-required">投产日期：</label>
          <div class="col-sm-3">
            <div class="input-group date">
              <input
                name="dev_tcrq"
                th:value="${#dates.format(gzmx_device.dev_tcrq, 'yyyy-MM-dd')}"
                class="form-control"
                placeholder="yyyy-MM-dd"
                type="text"
                required
              />
              <span class="input-group-addon"
                ><i class="fa fa-calendar"></i
              ></span>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">精度等级：</label>
          <div class="col-sm-3">
            <input
              name="dev_jddj"
              th:field="*{dev_jddj}"
              class="form-control"
              type="text"
            />
          </div>
          <label class="col-sm-2 control-label">测量范围：</label>
          <div class="col-sm-3">
            <input
              name="dev_clfw"
              th:field="*{dev_clfw}"
              class="form-control"
              type="text"
            />
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-3 control-label">ABC分类：</label>
          <div class="col-sm-3">
            <select
              name="dev_abcfl"
              class="form-control m-b"
              th:with="type=${@dict.getType('abc_fl')}"
            >
              <option
                th:each="dict : ${type}"
                th:text="${dict.dictLabel}"
                th:value="${dict.dictValue}"
                th:field="*{dev_abcfl}"
              ></option>
            </select>
          </div>
          <label class="col-sm-2 control-label">设备状态：</label>
          <div class="col-sm-3">
            <select
              name="dev_sbzt"
              class="form-control m-b"
              th:with="type=${@dict.getType('sb_zt')}"
            >
              <option
                th:each="dict : ${type}"
                th:text="${dict.dictLabel}"
                th:value="${dict.dictValue}"
                th:field="*{dev_sbzt}"
              ></option>
            </select>
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-3 control-label">出厂编号：</label>
          <div class="col-sm-3">
            <input
              name="dev_ccbh"
              th:field="*{dev_ccbh}"
              class="form-control"
              type="text"
            />
          </div>
          <label class="col-sm-2 control-label">仪表编号：</label>
          <div class="col-sm-3">
            <input
              name="dev_ybbh"
              th:field="*{dev_ybbh}"
              class="form-control"
              type="text"
            />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">计划检定日期：</label>
          <div class="col-sm-3">
            <div class="input-group date">
              <input
                name="dev_jhjdrq"
                th:value="${#dates.format(gzmx_device.dev_jhjdrq, 'yyyy-MM-dd')}"
                class="form-control"
                placeholder="yyyy-MM-dd"
                type="text"
              />
              <span class="input-group-addon"
                ><i class="fa fa-calendar"></i
              ></span>
            </div>
          </div>
          <label class="col-sm-2 control-label">设备类型：</label>
          <div class="col-sm-3">
            <!--  <input name="dev_sblx_name" th:field="*{dev_sblx_name}" class="form-control" type="text">
                  -->
            <select
              id="dev_sblx_id"
              name="dev_sblx_id"
              class="form-control m-b"
            ></select>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">是否检定：</label>
          <div class="col-sm-3">
            <input
              name="dev_isjd"
              th:field="*{dev_isjd}"
              class="form-control"
              type="text"
            />
          </div>
          <label class="col-sm-2 control-label">是否报废：</label>
          <div class="col-sm-3">
            <input
              name="dev_isbf"
              th:field="*{dev_isbf}"
              class="form-control"
              type="text"
            />
          </div>
        </div>
        <!-- 
             <div class="form-group">    
                <label class="col-sm-3 control-label">单位名称：</label>
                <div class="col-sm-3">
                    <input name="dept_name" th:field="*{dept_name}" class="form-control" type="text">
                </div>
                  <label class="col-sm-2 control-label">作业区名称：</label>
                <div class="col-sm-3">
                    <input name="zyq_name" th:field="*{zyq_name}" class="form-control" type="text">
                </div>
            </div>
             -->
        <div id="element2" class="row">
          <div class="col-sm-1" style="align: right">安装点位:</div>
          <div class="col-sm-2">
            <select
              name="dev_azdw1_id"
              id="first"
              style="width: 120px"
              class="first form-control m-b"
            ></select>
          </div>
          <div class="col-sm-2">
            <select
              name="dev_azdw2_id"
              id="second"
              style="width: 120px"
              class="second form-control m-b"
            ></select>
          </div>
          <div class="col-sm-2">
            <select
              name="dev_azdw3_id"
              id="third"
              style="width: 120px"
              class="third form-control m-b"
            ></select>
          </div>
          <div class="col-sm-2">
            <select
              name="dev_azdw4_id"
              id="fourth"
              style="width: 120px"
              class="fourth form-control m-b"
            ></select>
          </div>
          <div class="col-sm-2">
            <select
              name="dev_azdw5_id"
              id="fifth"
              style="width: 120px"
              class="fifth form-control m-b"
            ></select>
          </div>
        </div>
        <!--  
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备类型ID：</label>
                <div class="col-sm-8">
                    <input name="dev_sblx_id" th:field="*{dev_sblx_id}" class="form-control" type="text">
                </div>
            </div>
          
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装区域ID：</label>
                <div class="col-sm-8">
                    <input name="dev_azqy_id" th:field="*{dev_azqy_id}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称1：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw1_name" th:field="*{dev_azdw1_name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID1：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw1_id" th:field="*{dev_azdw1_id}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称2：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw2_name" th:field="*{dev_azdw2_name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID2：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw2_id" th:field="*{dev_azdw2_id}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称3：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw3_name" th:field="*{dev_azdw3_name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID3：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw3_id" th:field="*{dev_azdw3_id}" class="form-control" type="text">
                </div>
            </div>
            
             
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属单位代码：</label>
                <div class="col-sm-8">
                    <input name="ssdw_dm" th:field="*{ssdw_dm}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属单位名称：</label>
                <div class="col-sm-8">
                    <input name="ssdw_name" th:field="*{ssdw_name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位ID：</label>
                <div class="col-sm-8">
                    <input name="deptId" th:field="*{deptId}" class="form-control" type="text">
                </div>
            </div>
           
            <div class="form-group">    
                <label class="col-sm-3 control-label">部门ID：</label>
                <div class="col-sm-8">
                    <input name="bm_id" th:field="*{bm_id}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">部门名称：</label>
                <div class="col-sm-8">
                    <input name="bm_name" th:field="*{bm_name}" class="form-control" type="text">
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">点位ID：</label>
                <div class="col-sm-8">
                    <input name="SourceTag" th:field="*{SourceTag}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">点位名称：</label>
                <div class="col-sm-8">
                    <input name="Description" th:field="*{Description}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID4：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw4_id" th:field="*{dev_azdw4_id}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID5：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw5_id" th:field="*{dev_azdw5_id}" class="form-control" type="text">
                </div>
            </div>
            -->
      </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
              var prefix = ctx + "Gzmx_device/Gzmx_device";
              $("#form-Gzmx_device-edit").validate({
                  focusCleanup: true
              });
              var roles=[[${currentUser.roles}]];
              var dataScope=roles[0].dataScope;
              var dept_id=[[${currentUser.deptId}]];
              var dept=[[${dept}]];
              var ancestors=dept.ancestors;
              var bm_id=dept.deptId;

              if(ancestors.split(",").length>4){
              	dept_id=ancestors.split(",")[4];
              }
      $(function(){
      	initdev_sblx_name();
      	initfirst("1");
      });
              function submitHandler() {
              	var str_dev_name=$("#dev_name").val();
              	var str_dev_ggxh=$("#dev_ggxh").val();
              	var str_dev_sccj=$("#dev_sccj").val();


              	$("#dev_name").val(str_dev_name.replace(/\s*/g,""));

              	$("#dev_ggxh").val(str_dev_ggxh.replace(/\s*/g,""));
              	$("#dev_sccj").val(str_dev_sccj.replace(/\s*/g,""));

              	var str_dev_sblx_id=$("#dev_sblx_id").val();
              	if(str_dev_sblx_id==""){
              		$.modal.alertWarning("未选取设备类型，请核对");
              		return false;
              	}

              	var str_first=$("#first").val();
              	var str_second=$("#second").val();
              	var str_third=$("#third").val();
              	var str_fourth=$("#fourth").val();
              	var str_fifth=$("#fifth").val();


              	if(str_first==""||str_second==""||str_third==""||str_fourth==""||str_fifth==""){
              		$.modal.alertWarning("未选取生产点位，请核对");
              		return false;
              	}

                  if ($.validate.form()) {
                      $.operate.save(prefix + "/edit", $('#form-Gzmx_device-edit').serialize());
                  }
              }

              $("input[name='dev_ccrq']").datetimepicker({
                  format: "yyyy-mm-dd",
                  minView: "month",
                  autoclose: true
              });

              $("input[name='dev_jhjdrq']").datetimepicker({
                  format: "yyyy-mm-dd",
                  minView: "month",
                  autoclose: true
              });

              $("input[name='dev_tcrq']").datetimepicker({
                  format: "yyyy-mm-dd",
                  minView: "month",
                  autoclose: true
              });
              function initdev_sblx_name(){
              	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
              	//var $provinceHid = $("#"+objDivId).find('input.province');
                  $.ajax({
                      type: "post",
                      url: "/gzmx_sblx_fjd/fjd/list_all",
                      data: {
                          "id" :"",
                      },
                      success: function(result) {
                      	//alert(JSON.stringify(result.rows));
                          var rows = result.length;
                          console.log(result, 'res');
                          //alert(rows);
                          var html = `<option value="">请选择</option>`
                          for (let i = 0; i < result.rows.length; i++) {
                              html+=`<option value="`+result.rows[i].id+`">`+result.rows[i].lx_name+`</option>`
                          }
                          $("#dev_sblx_id").html(html);
                          $("#dev_sblx_id").find("option").each(function(){
                          	$(this).removeAttr("selected");
                         		if($(this).val()==[[${gzmx_device.dev_sblx_id}]]){
                         			$(this).attr("selected","selected");
                         			//provenceChange(objDivId);
                         		}
                         	});
                          $("#dev_sblx_id").change(function (){
                          	$("#dev_sblx_name").val($(this).find('option:selected').text());
                          	//$("#dev_azdw1_name").val($(this).find('option:selected').text());
                          	//initsecond($("#first").val());
                          //	$provinceHid.val($provinceSelect.find("option:selected").text());
                          //	provenceChange(objDivId);
                          });
                      },
                      error: function(error) {
                          $.modal.alertWarning(error);
                      }
                  });
              }

              function initfirst(objDivId){
              	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
              	//var $provinceHid = $("#"+objDivId).find('input.province');
                  $.ajax({
                      type: "post",
                      url: "/gzmx_scdw/gzmx_scdw/list",
                      data: {
                          "jb" : objDivId,
                      },
                      success: function(result) {
                      	//alert(JSON.stringify(result.length));

                          var rows = result.length;
                          //alert(rows);
                          var html = `<option value="">请选择</option>`
                          for (let i = 0; i < result.length; i++) {
                          	if(dataScope==1){
                          		html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                          	}else{
                          		if(result[i].deptId==dept_id){
                          			html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                          		}
                          	}
                          }
                          $("#first").html(html);
                          $("#first").change(function (){
                          	$("#dev_azdw1_name").val($(this).find('option:selected').text());
                          	initsecond($("#first").val());
                          //	$provinceHid.val($provinceSelect.find("option:selected").text());
                          //	provenceChange(objDivId);
                          });
                          $("#first").find("option").each(function(){
                          	$(this).removeAttr("selected");
                         		if($(this).val()==[[${gzmx_device.dev_azdw1_id}]]){
                         			$(this).attr("selected","selected");
                         			initsecond([[${gzmx_device.dev_azdw1_id}]]);
                              console.log([[${gzmx_device.dev_azdw1_id}]], '[[${gzmx_device.dev_azdw1_id}]]');
                         		}
                         	});
                      },
                      error: function(error) {
                          $.modal.alertWarning(error);
                      }
                  });
              }
              function initsecond(objDivId){
              	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
              	//var $provinceHid = $("#"+objDivId).find('input.province');
                  $.ajax({
                      type: "post",
                      url: "/gzmx_scdw/gzmx_scdw/list",
                      data: {
                          "fdwdm" : objDivId,
                      },
                      success: function(result) {
                      	//alert(JSON.stringify(result.length));

                          var rows = result.length;
                          //alert(rows);
                          var html = `<option value="">请选择</option>`
                          for (let i = 0; i < result.length; i++) {
                          	if(ancestors.split(",").length>4){

                          		if(result[i].dept_id_id==bm_id){
                                      html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`

                          		}
                          	}else{
                                  html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`

                          	}
                          }
                          $("#second").html(html);
                          $("#second").change(function (){
                          initthird($("#second").val());
                          $("#dev_azdw2_name").val($(this).find('option:selected').text());
                          //	$provinceHid.val($provinceSelect.find("option:selected").text());
                          //	provenceChange(objDivId);
                          });
                          $("#second").find("option").each(function(){
                          	$(this).removeAttr("selected");
                         		if($(this).val()==[[${gzmx_device.dev_azdw2_id}]]){
                         			$(this).attr("selected","selected");
                         			initthird([[${gzmx_device.dev_azdw2_id}]]);
                         		}
                         	});
                      },
                      error: function(error) {
                          $.modal.alertWarning(error);
                      }
                  });
              }

              function initthird(objDivId){
              	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
              	//var $provinceHid = $("#"+objDivId).find('input.province');
                  $.ajax({
                      type: "post",
                      url: "/gzmx_scdw/gzmx_scdw/list",
                      data: {
                          "fdwdm" : objDivId,
                      },
                      success: function(result) {
                      	//alert(JSON.stringify(result.length));

                          var rows = result.length;
                          //alert(rows);
                          var html = `<option value="">请选择</option>`
                          for (let i = 0; i < result.length; i++) {
                              html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                          }
                          $("#third").html(html);
                          $("#third").change(function (){
                          	 initfourth($("#third").val());
                          	 $("#dev_azdw3_name").val($(this).find('option:selected').text());
                          //	$provinceHid.val($provinceSelect.find("option:selected").text());
                          //	provenceChange(objDivId);
                          });
                          $("#third").find("option").each(function(){
                          	$(this).removeAttr("selected");
                         		if($(this).val()==[[${gzmx_device.dev_azdw3_id}]]){
                         			$(this).attr("selected","selected");
                         			initfourth([[${gzmx_device.dev_azdw3_id}]]);
                         		}
                         	});
                      },
                      error: function(error) {
                          $.modal.alertWarning(error);
                      }
                  });
              }
              function initfourth(objDivId){
              	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
              	//var $provinceHid = $("#"+objDivId).find('input.province');
                  $.ajax({
                      type: "post",
                      url: "/gzmx_scdw/gzmx_scdw/list",
                      data: {
                          "fdwdm" : objDivId,
                      },
                      success: function(result) {
                      	//alert(JSON.stringify(result.length));

                          var rows = result.length;
                          //alert(rows);
                          var html = `<option value="">请选择</option>`
                          for (let i = 0; i < result.length; i++) {
                              html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                          }
                          $("#fourth").html(html);
                          $("#fourth").change(function (){
                          	 initfifth($("#fourth").val());
                          	 $("#dev_azdw4_name").val($(this).find('option:selected').text());
                          //	$provinceHid.val($provinceSelect.find("option:selected").text());
                          //	provenceChange(objDivId);
                          });
                          $("#fourth").find("option").each(function(){
                          	$(this).removeAttr("selected");
                         		if($(this).val()==[[${gzmx_device.dev_azdw4_id}]]){
                         			$(this).attr("selected","selected");
                         			initfifth([[${gzmx_device.dev_azdw4_id}]]);
                         		}
                         	});
                      },
                      error: function(error) {
                          $.modal.alertWarning(error);
                      }
                  });
              }
              function initfifth(objDivId){
              	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
              	//var $provinceHid = $("#"+objDivId).find('input.province');
                  $.ajax({
                      type: "post",
                      url: "/gzmx_scdw/gzmx_scdw/list",
                      data: {
                          "fdwdm" : objDivId,
                      },
                      success: function(result) {
                      	//alert(JSON.stringify(result.length));
                      	 console.log(result, 'result');
                          var rows = result.length;
                          //alert(rows);
                          var html = `<option value="">请选择</option>`
                          for (let i = 0; i < result.length; i++) {
                              html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                          }
                          $("#fifth").html(html);
                          $("#fifth").change(function (){
                          	$("#dev_azdw5_name").val($(this).find('option:selected').text());
                          	// initfifth($("#fourth").val());
                          //	$provinceHid.val($provinceSelect.find("option:selected").text());
                          //	provenceChange(objDivId);
                          });
                          $("#fifth").find("option").each(function(){
                          	$(this).removeAttr("selected");
                         		if($(this).val()==[[${gzmx_device.dev_azdw5_id}]]){
                         			$(this).attr("selected","selected");
                         		//	initfifth([[${gzmx_device.dev_azdw4_id}]]);
                         		}
                         	});
                      },
                      error: function(error) {
                          $.modal.alertWarning(error);
                      }
                  });
              }
    </script>
  </body>
</html>
